using GameCore;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;

public class CoinItem : MonoBehaviour
{
    //public AudioClip clip;
    public string clipSTR;

    private void Awake()
    {
        EventManager.Instance.Register<bool>(EventName.GameOverEvent, GameOver);
    }

    private void OnDestroy()
    {
        EventManager.Instance.Unregister<bool>(EventName.GameOverEvent, GameOver);
    }

    private void GameOver(bool obj)
    {
        gameObject.SetActive(false);
    }


    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            //collision.gameObject.GetComponent<PlayerController>().PlayAudio(clip);
            collision.gameObject.GetComponent<PlayerController>().PlayAudio(clipSTR);
            EventManager.Instance.Send<int>(EventName.AddCoinEvent, 1);
            AssetsManager.Instance.FreeObject(gameObject);
            //Destroy(gameObject);
        }
    }

}
